﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace Royaumes_Libres.Database
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public static class cValidate
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        /// <remarks>Patrick Chabot</remarks>
        public static bool CheckEmailExist(string email)
        {
            SqlCommand cmd = cSQL.GetDbSiteCommand();

            cmd.Connection.Open();
            cmd.CommandText = "cde.spCheckEmailExist";

            cmd.Parameters.Add(cSQL.Param("@Email", email, SqlDbType.VarChar));

            int result = (int)cmd.ExecuteScalar();

            cmd.Connection.Close();

            if (result == 1) { return false; }
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        /// <remarks>Patrick Chabot</remarks>
        public static bool CheckUsernameExist(string username)
        {
            SqlCommand cmd = cSQL.GetDbSiteCommand();

            cmd.Connection.Open();
            cmd.CommandText = "cde.spCheckUsernameExist";

            cmd.Parameters.Add(cSQL.Param("@Username", username, SqlDbType.VarChar));

            int result = (int)cmd.ExecuteScalar();

            cmd.Connection.Close();

            if (result < 0) { return false; }
            return true;
        }

        public static bool CheckPassword(string Password, string PasswordAgain)
        {
            if (Password == PasswordAgain) { 
                return true; 
            }
            return false;
        }
    }
}